// pages/shop/product/Thematic/Thematic.js
const call = require('../../../../utils/request.js');
const utils = require('../../../../utils/util.js');
const recomList = require('../../shopList.js');

Component({
  lifetimes: {
    attached() {
      // 在组件实例进入页面节点树时执行
      var that = this;
      const url = `/5cdcc1ea7c2292738d1e6b74/example/getCatalogList`;
      const params = {};
      call.postData(url, params,
        res => {
          const shopList = res.data.data.elementList.goods[this.properties.index]; //获取店铺列表
          const shopPro = shopList.foods; //获取店铺商品
          for (var i = 0; i < shopPro.length; i++) {//给商品附加店铺名（后续会撤销）
            shopPro[i].shopName = that.properties.shopName
          }
          that.setData({//生成专题列表
            catalogList: shopPro
          })
        },
        err => {
          console.log(err);
        }, 'mock')
    },
    detached() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  options: {
    styleIsolation: 'apply-shared'
  },
  /**
   * 组件的属性列表
   */
  properties: {
    shopName: {
      type: String,
      value: '一箱好货'
    },
    index: {
      type: Number,
      value: 0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    catalogList: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onDetail(e) {
      var that = this;
      const action = e.currentTarget.dataset.action;
      //把当前点击数据存入缓存
      wx.setStorage({
        key: 'detail',
        data:[that.data.catalogList[e.currentTarget.dataset.index]]
      })
      //打开页面
      utils.openPage(action, {
        productId: '123'
      })
    }
  }
})